# 添加一个登录验证的功能
def check(fn):
    print("装饰器函数执行了")

    def inner():
        print("请先登录....")
        fn()

    return inner


# def logging(fn):
#     def inner(num1, num2):
#         print("正在努力计算")
#         res = fn(num1, num2)
#         return res
#
#     return inner


def logging(fn):
    def inner(num1, num2):
        print("--正在努力计算--")
        rt = fn(num1, num2)
        return rt

    return inner


# 使用语法糖方式来装饰函数
@check
def comment():
    print("发表评论")


@logging
def sum_num(a, b):
    re = a + b
    return re


if __name__ == '__main__':
    # 案例一
    comment()

    print("\n----分界线----\n")

    # 案例二：装饰带有参数、返回值的函数
    result = sum_num(1, 2)
    print(result)
